#include <vector>

using namespace std;

class Solution
{
public:
    vector<int> productExceptSelf(vector<int> &nums)
    {
        // 算出当前值的前缀积和后缀积
        vector<int> res(nums.size(), 1);
        int p = 1;
        int t = 1;
        for (int i = 0; i < nums.size(); ++i)
        {
            res[i] = p;
            p *= nums[i];
        }
        p = 1;
        for (int i = nums.size() - 1; i >= 0; --i)
        {
            res[i] *= p;
            p *= nums[i];
        }
        return res;
    }
};